package com.dongbao.dialog;

import com.dongbao.module.TemplateDto;
import com.intellij.openapi.ui.DialogWrapper;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.*;

public class ChooseTemplateDialog extends DialogWrapper {
    private JPanel contentPane = new JPanel();;
    private JButton buttonOK;
    private JButton buttonCancel;

    private TemplateDto templateDto;

    private String selectCheck;

    public ChooseTemplateDialog(TemplateDto templateDto){
        super(true);
        this.templateDto = templateDto;
        init();
        setTitle("选择模板");
    }
    public ChooseTemplateDialog(String title){
        super(true);
        init();
        setTitle(title);

    }

    @Override
    protected @Nullable JComponent createCenterPanel() {

        String[] array = new String[]{
                "java使用:  "+this.templateDto.getJavaTemplate(),
                "html使用:  "+this.templateDto.getHtmlTemplate(),
                "js使用:  "+this.templateDto.getJsTemplate(),
                "模板使用:  "+this.templateDto.getOrgTemplate(),
        };
        final JList jList = new JList(array);
        jList.addListSelectionListener(new ListSelectionListener(){
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if(!jList.getValueIsAdjusting()){	//设置只有释放鼠标时才触发
                    selectCheck = jList.getSelectedValue().toString().substring(jList.getSelectedValue().toString().indexOf(":")+3);
                }
            }
        });
        contentPane.add(jList);
        return contentPane;
    }

    public String getCheckValue() {

        return this.selectCheck;
    }
}
